<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Admin\Controller;
use Think\Controller;
class  CommonController extends Controller {
    function __construct() {
        parent::__construct();//避免覆盖
        
        $nowca = CONTROLLER_NAME. "-" .ACTION_NAME;//获取当前访问的路径
        
         $adname = $_SESSION['admin'];
         $id = $_SESSION['adid'];//根据当前的登录的管理员id获取管理员信息
         //dump($adname);
         
         //未登录判断，未登录直接调转到登录页面
         $loginca = "Login-index,Login-codes,Index-help";
         if(empty($adname) && strpos($loginca, $nowca) === false){
            //$this->redirect('Admin/Login/index');
             $url = __MODULE__;
            echo '<literal><script>window.top.location.href="' .$url.'/Login/index";</script></literal>';                 
             exit;
         }
         
         $admininfo = D('Admin')->find($id);
         $roleid = $admininfo['roleid'];
         //根据管理员信息获取用户组和管理权限
         $roleinfo = D('Rule')->find($roleid);
         $authca = $roleinfo['role-auth-ca'];
         
         
         //允许用户访问的公共权限
         $allwca = "Login-index,Login-codes,Login-logout,Index-index,Index-left,Index-top,Index-main,Index-help";
         //对比当前访问地址和拥有权限并单独声明超级管理员权限        
         if(strpos($authca, $nowca) === false && strpos( $allwca, $nowca) === false && $adname !== 'admin') {
              echo $nowca;
             exit("您没有该模块的权限");
            
         }
    }
}

